<?php


namespace App\Models;


use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Model;

class CoUserBalanceLog extends Model
{
    use HasDateTimeFormatter;
    protected $table = 'co_user_balance_log';

    /**
     * 添加记录
     * @param $user_id 用户ID
     * @param $type 记录类型：1收入 2处罚 3提现
     * @param $money 金额
     * @param $remark
     */
    public static function add($user_id,$type,$money,$remark=''){
        if(empty($remark)){
            if($type==1){
                $remark = '订单收入';
            }elseif ($type==2){
                $remark ='处罚';
            }else{
                $remark = '提现';
            }
        }
        $CoUserBalanceLog = new CoUserBalanceLog();
        $CoUserBalanceLog->user_id = $user_id;
        $CoUserBalanceLog->type = $type;
        $CoUserBalanceLog->money = $money;
        $CoUserBalanceLog->remark = $remark;
        return $CoUserBalanceLog->save();
    }
}
